<?php

/**
 * MovieForm class.
 * MovieForm is the data structure for keeping
 * movie form data. It is used by the 'create' action of 'MovieController'.
 */
class MovieForm extends CFormModel {

    public $wikipediaUrl;
    public $youtubeId;
    public $kpId;
    public $sourceImage;
    public $freeImage;

    /**
     * Declares the validation rules.
     * The rules state that username and password are required,
     * and password needs to be authenticated.
     */
    public function rules() {
        return array(
            array('sourceImage, freeImage, wikipediaUrl, youtubeId, kpId', 'required'),
            array('sourceImage, wikipediaUrl, youtubeId', 'length', 'max' => 255),
            array('kpId', 'length', 'max' => 10),
        );
    }

    /**
     * Declares attribute labels.
     */
    public function attributeLabels() {
        return array(
            'wikipediaUrl' => Yii::t('default', 'Wikipedia URL'),
            'youtubeId' => Yii::t('default', 'Youtube ID'),
            'kpId' => Yii::t('default', 'KinoPoisk ID'),
            'sourceImage' => Yii::t('default', 'Source Image'),
            'freeImage' => Yii::t('default', 'Free Image'),
        );
    }

    /**
     * Delete records by movie ID
     * 
     * @param int $movieId  Contains ID of movie
     */
    public function deleteByMovie($movieId) {
        $this->deleteAll('movie_id = :movieId', array(':movieId' => $movieId));
    }

}
